import Vue from 'vue'
import VueRouter from "vue-router";
import Login from '../components/Login.vue';
import Home from "../components/Home";
import acommodity from '../components/adminlogin/acommodity'
import welcome from "../components/welcome";
import apurchasedetails from "../components/adminlogin/apurchasedetails";
import apurchasemain from "../components/adminlogin/apurchasemain";
import astaff from "../components/adminlogin/astaff";
import asupplier from "../components/adminlogin/asupplier";
import ccommodity from "../components/commonlogin/ccommodity";
import cpurchasedetail from "../components/commonlogin/cpurchasedetail";
import cpurchasemain from "../components/commonlogin/cpurchasemain";


Vue.use(VueRouter)


const router  = new VueRouter({
      routes:[
        { path: '/',redirect: '/login'},
        //自动重定向  用户从‘/’ 定向到‘/login’
        {path: '/login',component: Login},
        {path: '/home', component: Home,redirect: '/welcome',
          //redirect是重定向的意思   就是你在home页面点击他就给你定向到/welcome页面
          //home这个路由中新增一个子路由
          children: [
            { path: '/welcome', component: welcome},
            { path: '/acm', component: acommodity},
            { path: '/apd', component: apurchasedetails},
            { path: '/apm', component: apurchasemain},
            { path: '/asl', component: asupplier},
            { path: '/asf', component: astaff},
            { path: '/cpd', component: cpurchasedetail},
            { path: '/cpm', component: cpurchasemain},
            { path: '/ccm', component: ccommodity},
          ]
        }
      ]
    }
)

//挂载路由导航

// router.beforeEach((to, from,next) =>{
//   //to 表示要访问的路径
//   //from表示从哪个路径跳转而来
//   //next是一个函数表示放行
//   //next() next('/login')强制跳转
//   //如果我自己输入的路径是http://localhost:8080/#/Home按照常理说肯定是不行的
//   //所以要给他来一个强制跳转 只能通过登录来进入home这个页面
//   // if(to.path === '/login') return next()
//   // //获取token
//   // const tokenStr = window.sessionStorage.getItem('token')
//   // if(!tokenStr) return next('/login')
//   // next()
//
// })
export default router
